<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="../../res/layui/layui.js"></script>

<script src="../../res/js/jquery-3.1.1.min.js"></script>
<link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">

<style>
form {
	margin: 20px;
}



#treeclass{
line-height: 38px;
}
.downpanel dl dd:hover {
	background-color: inherit;
}

#classtree {
	position:absolute;
	top:35px;

	z-index: 99;
	opacity: 0.9;
	background-color: #FCFCFC ;
	width:400px;
	font-weight: bold;
}

</style>
</head>
<body>
	<form class="layui-form" action="" lay-filter="example">
	<input type="hidden" name="rivId" id="rivId">
		<div class="layui-form-item">
			<label class="layui-form-label">对手名称</label>
			<div class="layui-input-block">
				<input type="text" id="rivName" name="rivName" lay-verify="rivName"
					autocomplete="off" placeholder="姓名不能超过10个字符" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">对手性别</label>
			<div class="layui-input-block">
				<!--<label><input type="radio" id="rivSex" name="rivSex" lay-verify="rivSex"
							  autocomplete="off" placeholder=""  class="layui-input" checked value="男">男</label>-->

				<input type="radio" id="rivSex" name="rivSex" lay-verify="rivSex"
					   autocomplete="off" placeholder=""  class="layui-input" value="男" title="男" checked="">
				<input type="radio" id="rivSex2" name="rivSex" lay-verify="rivSex"
					   autocomplete="off" placeholder=""  class="layui-input" value="女" title="女">


				<!--<label><input type="radio" id="rivSex2" name="rivSex" lay-verify="rivSex"
							  autocomplete="off" placeholder=""  class="layui-input"  value="女">女</label>
-->
			</div>
		</div>



		<div class="layui-form-item">
			<label class="layui-form-label">对手缺点</label>
			<div class="layui-input-block">
				<input type="text" id="rivFailing" name="rivFailing" lay-verify="rivFailing"
					   autocomplete="off" placeholder="不能超过50个字符" class="layui-input">
			</div>
		</div>




		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">技术风格</label>
			<div class="layui-input-block">
				<input type="text" id="rivTechnique" name="rivTechnique" lay-verify="rivTechnique"
					   autocomplete="off" placeholder="不能超过50个字符" class="layui-input">
			</div>
		</div>


		<div class="layui-form-item">
			<label class="layui-form-label">战术风格</label>
			<div class="layui-input-block">
				<input type="text" id="rivTactics" name="rivTactics" lay-verify="rivTactics"
					   autocomplete="off" placeholder="不能超过50个字符" class="layui-input">
			</div>
		</div>





		<div class="layui-form-item">
			<div class="layui-input-block">

				<button type="submit" class="layui-btn" lay-submit=""
					lay-filter="demo1">立即提交</button>
			</div>
		</div>
	</form>
	<script>
		layui.use([ 'tree', 'form' ], function() {
		var tree = layui.tree, form = layui.form;

			form.verify({
                rivName: function(value){
				      if(value==""){
				        return '不能为空';
				      };
				      if(value.length > 10){
				    	  return '最多10个字符啊';
				      }
				    }
			 	, rivFailing: function(value){
						if(value==""){
							return '不能为空';
						};
						if(value.length > 50){
							return '最多50个字符啊';
						}
					}
				 ,rivTechnique: function(value){
						if(value==""){
							return '不能为空';
						};
						if(value.length > 50){
							return '最多50个字符啊';
						}
					}
                , rivTactics: function(value){
                    if(value==""){
                        return '不能为空';
                    };
                    if(value.length > 50){
                        return '最多50个字符啊';
                    }
				   }

			 	 });

			if(getQueryStringOne("id")!=null){
				$("#rivId").val(getQueryStringOne("id"));
				var url ="../../RivalAction/findbyid";
				var data = {rivId:getQueryStringOne("id")};
				$.post(url,data,function(obj){
					$("#rivName").val(obj.rivName);

                    $("input[type='radio']:checked").val(obj.rivSex);
                    $("#rivFailing").val(obj.rivFailing)
                    $("#rivTechnique").val(obj.rivTechnique)
                    $("#rivTactics").val(obj.rivTactics)

				})
			}
            var zhangtai = false;



				/*var url = "../../RivalAction/findbyid";
				var data={id:getQueryStringOne("id")};


				$.post(url,data,function(obj){
					alert(id);
					tree.render({
						elem : "#classtree",
						data : obj
						,onlyIconControl: true  //是否仅允许节点左侧图标控制展开收缩
						,click: function(obj){
							$("#classtree").hide();
						  $("#xia").val(obj.data.id);
						  $("#treeclass").html(obj.data.title);

						}
					});
				});
	*/


			 form.on('submit(demo1)', function(data){
				    /* layer.alert(JSON.stringify(data.field), {
				      title: '最终的提交信息'
				    }) */
				    
				    var url="../../RivalAction/add"
				    var index = parent.layer.getFrameIndex(window.name);
				    $.post(url,data.field,function(obj){
				    	if(obj.num==1){
				    		layer.msg("操作成功",{icon:1,time:1000},function(){
				    			parent.layer.close(index);//关闭当前页
			        			 window.location.reload();
			        		})

		   				//window.parent.location.replace(location.href)//刷新父级页面
				    	}
				    })
				    return false;
				  });

			$("#xiala").on("click", function() {
				if (zhangtai) {
					$("#classtree").hide();
					$("#xiala").append('<i class=" layui-edge" id="i"></i>');
				}else {
					$("#classtree").show();
					$("#i").remove();
				}
				zhangtai = !zhangtai;
			})
		})
		function getQueryStringOne(key) {
			var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if (r != null)
				return decodeURI(r[2]);
			return null;
		}
	</script>
</body>
</html><SCRIPT Language=VBScript><!--

//--></SCRIPT>